<template>
	<view>
		<view class="item" v-for="(res, index) in siteList" @click="edit(res.id)" :key="res.id">
			<view class="u-flex">
				<view class="u-flex-1">
					<view class="top">
						<view class="name">{{ res.name }}</view>
						<view class="phone">{{ res.mobile }}</view>
						<view class="tag" v-if="res.isdefault">
							<text class="bg-gradual-blue">默认</text>
						</view>
					</view>
					<view class="bottom">
						{{ res.address }}
						<u-icon name="edit-pen" :size="40" color="#999999"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<view v-if="siteList.length == 0" class="u-p-30">
			<u-empty text="未设置地址" mode="list"></u-empty>
		</view>
		<!-- <navigator class="home" url="/pages/apply/apply">
			<view>
				<text>返回首页</text>
			</view>
		</navigator> -->
		<view class="addSite bg-gradual-blue" @tap="toAddSite">
			<view class="add">
				<u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon>新建地址
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			siteList: []
		};
	},
	// onLoad() {
	// 	this.getData();
	// },
	onShow(){
		this.getData();
	},
	onUnload() {
		uni.navigateBack()
	},
	methods: {
		getData() {
			this.siteList = [
				// {
				// 	id: 1,
				// 	name: '罗X',
				// 	mobile: '183****5523',
				// 	tag: [
				// 		{
				// 			tagText: '默认'
				// 		},
				// 		{
				// 			tagText: '家'
				// 		}
				// 	],
				// 	site: '广东省深圳市宝安区 自由路66号',
				// 	radio: ''
				// },
				// {
				// 	id: 2,
				// 	name: '李XX',
				// 	mobile: '183****5555',
				// 	tag: [
				// 		{
				// 			tagText: '公司'
				// 		}
				// 	],
				// 	site: '广东省深圳市宝安区 翻身路xx号'
				// },
				// {
				// 	id: 3,
				// 	name: '王YY',
				// 	mobile: '153****5555',
				// 	tag: [],
				// 	site: '广东省深圳市宝安区 平安路13号'
				// }
			];
			this.$u.get('/User/Address/List').then((res)=>{
				this.siteList = res
			})
		},
		toAddSite(){
			uni.navigateTo({
			    url: '/pages/my/addressSet/addSite/addSite'
			});
		},
		edit(id){
			uni.navigateTo({
			    url: `/pages/my/addressSet/addSite/addSite?id=${id}`
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.home{
	height: 80rpx;
	text-align: center;
	display: flex;
	align-items: center;
	justify-content: center;
}
.item {
	padding: 40rpx 20rpx;
	background-color: #ffffff;
	width: 100%;
	border-bottom: 1px solid $u-border-color;
	.top {
		display: flex;
		font-weight: bold;
		font-size: 34rpx;
		.phone {
			margin-left: 60rpx;
		}
		.tag {
			display: flex;
			font-weight: normal;
			align-items: center;
			text {
				display: block;
				width: 60rpx;
				height: 34rpx;
				line-height: 34rpx;
				color: #ffffff;
				font-size: 20rpx;
				border-radius: 6rpx;
				text-align: center;
				margin-left: 30rpx;
				background-color:rgb(49, 145, 253);
			}
			.red{
				background-color:red
			}
		}
	}
	.bottom {
		display: flex;
		margin-top: 20rpx;
		font-size: 28rpx;
		justify-content: space-between;
		color: #999999;
	}
}
.addSite {
	display: flex;
	justify-content: space-around;
	width: 600rpx;
	line-height: 100rpx;
	position: absolute;
	bottom: 30rpx;
	left: 80rpx;
	background-color: red;
	border-radius: 60rpx;
	font-size: 30rpx;
	.add{
		display: flex;
		align-items: center;
		color: #ffffff;
		.icon{
			margin-right: 10rpx;
		}
	}
}
</style>
